/**
 * Created by lesonli on 2016/11/17.
 */
import * as types from '../types'
import api from '../../api/modules/config'
import {
    get_list
} from '../../api/modules/product'

const state = {
    product_list: [],
    showLoading: false
}

// getters
// actions
const actions = {
    get_product_list({
            commit
        }, param) {
            if(state.product_list.length === 0)
            {
                commit(types.PRODUCT_SHOW_LOADING, param);
        get_list(param).then((res) => {
            if (res.data.res_code === 1) {
                commit(types.PRODUCT_LIST_LOADED, res.data.msg);
            }
        });
            }
        
    }
}
// mutations
const mutations = {
    [types.PRODUCT_SHOW_LOADING](state, param) {
        state.showLoading = true;
    },
    [types.PRODUCT_LIST_LOADED](state, param) {
        state.product_list = param;
        state.showLoading = false;
    }
}

export default {
    state,
    actions,
    mutations
}
